/*
 * MLXQServiceFactory.java
 */

package xq.marklogic;

import com.marklogic.xcc.ContentSource;
import com.marklogic.xcc.ContentSourceFactory;
import com.marklogic.xcc.exceptions.XccConfigException;
import java.net.URI;
import java.util.Map;
import xq.api.XQConfigException;
import xq.api.XQService;
import xq.api.XQServiceFactory;

public class MLXQServiceFactory extends XQServiceFactory {

	public boolean acceptsURI(URI connectionURI) {
		return "xcc".equals(connectionURI.getScheme());
	}
	
	public XQService create(URI connectionURI) throws XQConfigException {
		return create(connectionURI, null);
	}

	public XQService create(URI connectionURI, Map<String, ? extends Object> properties) throws XQConfigException {
		try {
			ContentSource contentSource = ContentSourceFactory.newContentSource(connectionURI);
			MLXQService service = new MLXQService();
			service.setContentSource(contentSource);
			return service;
		} catch (XccConfigException ex) {
			throw new XQConfigException("Failed to configure Mark Logic content source.", ex);
		}
	}
}
